﻿
// <copyright file="AbstractMonitorAtomicOperationSupported.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The AbstractMonitorAtomicOperationSupported class.
// </summary>


namespace SubhadraSolutions.Sharp.Utils.Threading
{
    using System;

    using SubhadraSolutions.Sharp.Utils.Validation;

    /// <summary>
    /// The AbstractMonitorAtomicOperationSupported class.
    /// </summary>
    public abstract class AbstractMonitorAtomicOperationSupported : IAtomicOperationSupported
    {
        /// <summary>
        /// The synchronize lock object
        /// </summary>
        private readonly object syncLockObject = new object();

        /// <summary>
        /// Gets the sync lock object.
        /// </summary>
        protected object SyncLockObject
        {
            get
            {
                return this.syncLockObject;
            }
        }

        /// <summary>
        /// Performs the atomic operation.
        /// </summary>
        /// <param name="action">
        /// The action.
        /// </param>
        public void PerformAtomicOperation(Action action)
        {
            Guard.ArgumentNotNull(action, "action");
            lock (this.syncLockObject)
            {
                action();
            }
        }
    }
}
